from selenium.webdriver.common.by import By
from base.base import Base
from selenium.webdriver import ActionChains
import time


class Page_Data(Base):

    topnav_locator = (By.XPATH,'(//li[contains(@class,"ant-menu-overflow-item")])[7]')
    topnav_nav_locator = (By.XPATH,'//span[text()="数据角色管理"]')
    user_name_locator = (By.XPATH,'//input[@placeholder="请输入角色名称"]')
    search_btn_locator = (By.XPATH,'//span[text()="查 询"]')
    reset_btn_locator = (By.XPATH,'//span[text()="重 置"]')
    list_locator = (By.XPATH,'//tbody//td[contains(@class,"ant-table-cell")]')
    search_empty_locator = (By.CLASS_NAME,'ant-empty-description')
    add_btn_locator = (By.XPATH,'//span[text()="新建"]')
    name_locator = (By.XPATH,'(//input[@placeholder="请输入角色名称"])[2]')
    remark_locator = (By.XPATH,'//textarea')
    confirm_btn_locator = (By.XPATH,'//span[text()="确 定"]')
    modify_btn_locator = (By.XPATH,'(//td//div[@class="ant-space-item"])[1]')
    delete_btn_locator = (By.XPATH,'(//a[@class="ele-text-danger"])[1]')
    delete_confirm_btn_locator = (By.XPATH,'//button[@class="ant-btn ant-btn-primary ant-btn-sm"]//span')


    def page_jump(self):
        time.sleep(0.5)
        action = ActionChains(self.driver)
        action.move_to_element(self.find(self.topnav_locator)).perform()
        action.click(self.find(self.topnav_nav_locator)).perform()

    def get_list(self):
        elms = self.finds(self.list_locator)
        values = []
        for index,elm in enumerate(elms):
            if index%4 != 3:
                values.append(self.get_text_elm(elm))
        return values
    
    def input_username_search(self,username):
        self.input(self.user_name_locator,username)

    def click_search_btn(self):
        self.click(self.search_btn_locator)

    def click_reset_btn(self):
        self.click(self.reset_btn_locator)

    def get_empty_text(self):
        return self.get_text(self.search_empty_locator)
    
    def click_add_btn(self):
        self.click(self.add_btn_locator)

    def input_name(self,name):
        self.input(self.name_locator,name)

    def input_remark(self,remark):
        self.input(self.remark_locator,remark)

    def click_confirm_btn(self):
        self.click(self.confirm_btn_locator)

    def click_modify_btn(self):
        self.click(self.modify_btn_locator)
    
    def click_delete_btn(self):
        self.click(self.delete_btn_locator)
    
    def click_delete_confirm_btn(self):
        self.click(self.delete_confirm_btn_locator)